<?php
namespace Modules\ShopAdmin\Http\Controllers;
use Illuminate\Http\Request;
use Modules\Admin\Http\Requests\CommonStatusRequest;
use Modules\Admin\Http\Requests\CommonDeleteRequest;
use Modules\ShopAdmin\Models\ShopUserInfo as ShopUserInfoModel;
use Modules\Admin\Models\Image as ImageModel;
class UserController extends CommonShopController
{
	/**
	 * @name  列表
	 */
    public function index()
    { 
		$status = ShopUserInfoModel::common_status();
        return view('shopadmin::user.index',compact('status'));
    }
	/**
	 * @name  列表数据
	 */
    public function data(Request $request)
    {
	    $model = ShopUserInfoModel::query();
		$params = $request->all();
		$params_data = $params;
		unset($params['key']);
		$model = query_condition($model,$params); 
        $res = $model
				->whereHas('user_one',function($query)use($params_data){
					if(!empty($params_data['key'])){
						$query->where('phone', 'like', '%' . $params_data['key'] . '%');
						$query->orWhere('nick_name', 'like', '%' . $params_data['key'] . '%');
					}
				})
				->with([
					'user_one.image_one'=>function($query){
						$query->select('id','url','status');
					},
					'user_one'=>function($query){
						$query->select('id','avatar_url','image_id','nick_name','avatar_url','gender','phone');
					}
				])
				->orderBy('id','desc')  
				->paginate($params['limit'])
				->toArray();	
		$res['data'] = (new ShopUserInfoModel())->data_image($res['data']);	
        return response()->json(['code' => 0, 'msg'   => config('admin.limit_msg'),'count' => $res['total'],'data'  => $res['data'],'rel'=>1]);
    }
	/**
	 * @name  调整菜单状态数据处理
	 */
    public function status(CommonStatusRequest $request,$id)
    {
		return (new ShopUserInfoModel())->common_status_update($request->all(),$id,route('shop_admin.user.index')); 
    }
	/**
	 * @name  删除数据处理
	 */
    public function destroy(CommonDeleteRequest $request)
    {
		return (new ShopUserInfoModel())->common_destroy($request->get('id'),route('shop_admin.user.index'));  
    }
}
